<?php

namespace app\api\controller\cps;

use app\common\controller\Api;



/**
 * 京东联盟接口
 */
class Jd extends Api
{
    protected $noNeedLogin = ['searchgoods','categoryGoods','recommendGoods','goodsDetail','couponInfo','getOrderList','unliquidated'];
    protected $noNeedRight = ['*'];

    /**
     * 关键词查询商品
     *
     */
    public function searchgoods()
    {
        try {
            //$parentId = input('parentId',0);//父类目id(一级父类目为0)
            //$grade = input('grade',0);//类目级别(类目级别 0，1，2 代表一、二、三级类目)
            $page = input('page',1);
            $keyword = input('keyword','');
            $cid1 = input('cid',0);
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->searchGoods($page,$keyword,$cid1);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }


        $this->success('请求成功',$res);
    }

    //商品类目查询接口
    public function categoryGoods()
    {
        try {
            $parentId = input('parentId',0);//父类目id(一级父类目为0)
            $grade = input('grade',0);//类目级别(类目级别 0，1，2 代表一、二、三级类目)
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->categoryGoods($parentId,$grade);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //猜你喜欢商品推荐
    public function recommendGoods()
    {
        try {
            $eliteId = input('eliteId',1);//频道ID：1.猜你喜欢、2.实时热销、3.大额券、4.9.9包邮
            $page = input('page',1);
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->recommendGoods($page,$eliteId);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //商品详情
    public function goodsDetail()
    {
        try {

            $sku_id = input('sku_id',0);
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->goodsDetail($sku_id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //优惠券领取情况查询接口
    public function couponInfo()
    {
        try {

            $coupon_url = input('coupon_url','');
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->couponInfo($coupon_url);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //获取网站/app跳转链接
    public function getAppUrl()
    {
        try {

            $materialId = input('materialId','');
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->getUrl($materialId);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //获取小程序跳转链接
    public function getWeappUrl()
    {
        try {

            $materialId = input('materialId','');
            $couponUrl = input('couponUrl','');
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->getWeappUrl($materialId,$this->auth->id,$couponUrl);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //查询推广订单及佣金信息
    public function getOrderList()
    {
        try {

            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->orderlist();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    public function unliquidated()
    {
        try {

            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->unliquidated();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //奖励订单查询
    public function getCommissionOrderList()
    {
        try {
            $page = input('page',1);
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->commission_order_list($page);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }
    //活动查询接口
    public function  activitySearch()
    {
        try {
            $page = input('page',1);
            $jd_model = new \app\api\model\cps\Jd();

            $res = $jd_model->activitySearch($page);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //
    public function  urllist()
    {
        try {
            $jd_model = new \app\api\model\cps\Jd();
            $res = $jd_model->urllist();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }
}
